﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DXWindowsApplication1.MainForm;
using System.IO;
using System.Diagnostics;

namespace DXWindowsApplication1.MainForm
{
    public class ListViewExplorer
    {
        string path = "";
        Support support = new Support();
        public string OpenFolderOnTreeView(TreeNode treenode, ListView listview) {

            if (treenode.Text.Equals("My Computer"))
            {
                path = support.GetDrivesItem(listview);
            }
            else {
                DirectoryInfo dirinfo = new DirectoryInfo(support.getPathDirectories(treenode));
                path = support.GetDirectoriesItem(dirinfo, listview);
            }
            return path;
        }

        public string OpenFolderBaseOnLink(string path, ListView listView) {
            string _path;
            if (path.Equals("My Computer"))
            {
                _path = support.GetDrivesItem(listView);
            }
            else {
                path = (path.EndsWith("\\")) ? path : (path + "\\");
                _path = support.GetDirectoriesItem(new DirectoryInfo(path), listView);
            }
            return path;
        }

        public string OpenFolderOnListview(ListViewItem item, ListView listview) {

            path = item.SubItems[4].Text;
            FileInfo fileinfo = new FileInfo(path);
            if (fileinfo.Exists)
            {
               
                Process.Start(path);
                return fileinfo.FullName;
            }
            else {
                DirectoryInfo dirinfo = new DirectoryInfo(path + "\\");
                string pathDir = support.GetDirectoriesItem(dirinfo, listview);
                return pathDir;
            }
             
        }

        public void OpenUpFolder(ref DevExpress.XtraEditors.TextEdit textEdit, ListView listview) { 
        
        }

       

    }
}
